﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace DrawWorkflow
{
    public enum DrawType
    {
        None, Line, Rectangle
    }

    public partial class Page : UserControl
    {
        DrawType drawType;
        bool isDrawing;
        Point startPosition;

        public Page()
        {
            InitializeComponent();
        }

        private void buttonDrawLine_Click(object sender, RoutedEventArgs e)
        {
            if (drawType == DrawType.Line)
            {
                drawType = DrawType.None;
            }
            else
            {
                drawType = DrawType.Line;
            }

            textBlockStatus.Text = drawType.ToString();
        }

        private void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            isDrawing = true;
            FrameworkElement element = sender as FrameworkElement;
            element.Cursor = Cursors.Stylus;

            startPosition = e.GetPosition(element);

        }

        private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (isDrawing)
            {
                isDrawing = false;
                FrameworkElement element = sender as FrameworkElement;
                element.Cursor = Cursors.Arrow;
                Point endPosition = e.GetPosition(element);

                VisualLine line = new VisualLine();
                line.X1 = startPosition.X;
                line.Y1 = startPosition.Y;
                line.X2 = endPosition.X;
                line.Y2 = endPosition.Y;

                line.Draw(canvas4Draw);
            }

        }

        private void Canvas_MouseMove(object sender, MouseEventArgs e)
        {

        }


    }
}
